﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Hmc.IM.Common.Base;

using Hmc.IM.Common;

namespace Hmc.IM.Client
{
    public partial class HomePageForm : Form
    {
        public HomePageForm()
        {
            InitializeComponent();
        }

        private void HomePageForm_Load(object sender, EventArgs e)
        {
            flpPanel1.BeginInvoke(new Action(InitData));
        }

        private void InitData()
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (sender, e) =>
            {
                try
                {
                    //List<SystemMessageEntity> list = ServiceInvokeHelper<StoreContractsClient>.Invoke(c => c.GetNewSystemMessageByUserId(LoginUserEntity.Token, 6, LoginUserEntity.SystemUserId));
                    //worker.ReportProgress(1, list);
                    //list = ServiceInvokeHelper<StoreContractsClient>.Invoke(c => c.GetTodayMessage(LoginUserEntity.Token, LoginUserEntity.OrganizationId));
                    //worker.ReportProgress(2, list);
                }
                catch (Exception ex)
                {
                    ////Recorder.Write(ex);
                }
            };
            worker.ProgressChanged += (sender, e) =>
            {
                //List<SystemMessageEntity> list = e.UserState as List<SystemMessageEntity>;
                //if (list != null && list.Count > 0)
                //{
                //    foreach (SystemMessageEntity item in list)
                //    {
                //        if (e.ProgressPercentage == 1)
                //            AddItem(item, flpPanel1);
                //        else if (e.ProgressPercentage == 2)
                //            AddItem(item, flpPanel2);
                //    }
                //}

            };
            worker.WorkerReportsProgress = true;
            worker.RunWorkerAsync();
        }

        //private void AddItem(SystemMessageEntity item, Control ctl)
        //{
        //    Label lb = new Label();
        //    lb.AutoEllipsis = true;
        //    lb.ForeColor = System.Drawing.Color.FromArgb(75, 75, 75);
        //    lb.Image = global::Hmc.IM.Client.Properties.Resources.home_lg1;
        //    lb.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
        //    lb.Margin = new System.Windows.Forms.Padding(10, 7, 3, 0);
        //    lb.Name = item.MessageId.ToString();
        //    lb.Size = new System.Drawing.Size(flpPanel1.Width - 2, 15);
        //    if (ctl == flpPanel1)
        //        lb.Text = string.Format("  [{0}]{1}", item.CreateTime.ToString("yyyy-MM-dd"), item.Content);
        //    else
        //        lb.Text = string.Format("  {0}", item.Content);
        //    ctl.Controls.Add(lb);
        //}
    }
}
